import { Module, VuexModule, Action } from "vuex-class-modules";
import { getLanguage, setLanguage } from "../settings/lang";
import { loadLanguage } from "@/framework/lang";

@Module({ generateMutationSetters: true })
export default class SystemStore extends VuexModule {
  lang = getLanguage();
  readonly baseUrl = process.env.VUE_APP_PUBLIC_PATH;

  /**
   * 设置语言
   * @param lang
   */
  @Action
  async setLanguage(lang: string) {
    await loadLanguage(lang);
    setLanguage(lang);
    this.lang = lang;
  }

  // @Action
  // async LoadConfig() {
  //   const resBody = await fetch(`${this.baseUrl}config.json`);
  //   const resJson = await resBody.json();
  // }
}
